package com.gitee.controller;

import com.gitee.enums.CookbookTypeEnum;
import com.gitee.enums.OrderStatusEnum;
import com.gitee.enums.OrderTypeEnum;
import com.gitee.service.IOrderService;
import com.gitee.vo.OrderVo;
import com.gitee.vo.PageVo;
import com.gitee.vo.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单管理
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @GetMapping
    public ResponseVo<PageVo<OrderVo>> list(String eatTime, Integer cookbookType, Integer orderStatus, Integer orderType,
                                            Integer pageNum, Integer pageSize) {
        if (cookbookType != null) {
            cookbookType = CookbookTypeEnum.of(cookbookType).getCode();
        }
        if (orderStatus != null) {
            orderStatus = OrderStatusEnum.of(orderStatus).getCode();
        }
        if (orderType != null) {
            orderType = OrderTypeEnum.of(orderType).getCode();
        }
        PageVo<OrderVo> orderVoPageVo = orderService.pageOrderVos(eatTime, cookbookType, orderStatus, orderType, pageNum, pageSize);
        return ResponseVo.ok(orderVoPageVo);
    }
}
